<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function sortArr(arr) {
        for (let i = 0; i < arr.length; i++) { //趟数
            for (let j = 0; j < arr.length - i - 1; j++) { //次数
                if (arr[j] > arr[j + 1]) {
                    let temp;
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }


    function mergeTwoLists(list1, list2) {
        // list1 = list1 + ',' + list2;
        // let sa = list1.split(',')
        // for (let i = 0; i < list2.length; i++) {
        //     list1.concat(list2);
        // }

        //两个链表合并
        let arr = list1.concat(list2);
        //排序
        return arr.sort();
        //  return sortArr(sa);
    };
    let list1 = [1, 2, 4];
    let list2 = [1, 3, 4];
    console.log(mergeTwoLists(list1, list2));
</script>

<!-- <script>
 //链表转数组
 function listArray(head) {
    if(!head) {
        return [];
    }
    var result = [];
    var p = head;
    while(p) {
        result.push(p.value)
        p = p.next;
    }
    return result;
}

var mergeTwoLists = function(list1, list2) {
    let l1 = listArray(list1);
    let l2 = listArray(list2);  
    let arr = l1.concat(l2);
    return arr.sort();    
};
</script> -->

</html>